﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using DICE_GS;

public class UnitChangeConfirmSceneManager : MonoBehaviour {
	public UILabel LeftNameText;
	public UILabel LeftLevelText;
	public UILabel LeftHPText;
	public UILabel LeftAttack;
	public UILabel LeftDefenseText;
	public UILabel LeftMoveText;
	public UILabel RightNameText;
	public UILabel RightLevelText;
	public UILabel RightHPText;
	public UILabel RightAttack;
	public UILabel RightDefenseText;
	public UILabel RightMoveText;
	
	// Use this for initialization
	void Start () {

		if (MyInfo.Instance.MyDeckMap.ContainsKey(MyInfo.Instance.MyCurrentDeck))
		{
			DeckInfo tmpDeck = MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck];
			if (tmpDeck != null)
			{
				{
					GameObject go = GameObject.Find("L_Face");
				
					CUnitData tmpUnitData = CUnitDataManager.Instance.GetUnitData(tmpDeck.SlotMap[MyInfo.Instance.LastSeletedUnitSlot].UnitClassID);

					if (tmpUnitData != null)
					{
						if (go != null)
						{
							UISprite tmpSprite = go.GetComponent<UISprite>() as UISprite;
							tmpSprite.spriteName = tmpUnitData.name;
							Debug.Log("L_Face -- " + tmpSprite.spriteName);
							Debug.Log(MyInfo.Instance.LastSeletedUnitSlot);
							Debug.Log(tmpDeck.SlotMap[MyInfo.Instance.LastSeletedUnitSlot].UnitClassID);
						}
						
						//temporary part to demo.
						//must be modified.
						LeftNameText.text = tmpUnitData.devname;
						LeftLevelText.text = tmpUnitData.grade.ToString();
						LeftHPText.text = tmpUnitData.max_hp.ToString();
						LeftAttack.text = tmpUnitData.attack_base.ToString();
						LeftDefenseText.text = tmpUnitData.defense_base.ToString();
						LeftMoveText.text = tmpUnitData.move_base.ToString();
					}
					else
					{
						LeftLevelText.text = "0";
						LeftHPText.text = "0";
						LeftNameText.text = "None";
						LeftAttack.text = "0";
						LeftDefenseText.text = "0";
						LeftMoveText.text = "0";
					}
				}

				{
					GameObject go = GameObject.Find("R_Face");

                    UnitInfo selectedUnitInfo = MyInfo.Instance.GetUnitInfoById(MyInfo.Instance.LastSelectedUnitDBID);
                    if (selectedUnitInfo != null)
					{
						if (go != null)
						{
							UISprite tmpSprite = go.GetComponent<UISprite>() as UISprite;
							tmpSprite.spriteName = selectedUnitInfo.unitData.name;
						}
						
						RightNameText.text = selectedUnitInfo.unitData.devname;
						RightLevelText.text = selectedUnitInfo.UnitLevel.ToString();
                        RightHPText.text = selectedUnitInfo.hp.ToString();
                        RightAttack.text = selectedUnitInfo.attack.ToString();
                        RightDefenseText.text = selectedUnitInfo.defense.ToString();
                        RightMoveText.text = selectedUnitInfo.move.ToString();
					}
				}
			}
		}
	}
}
